// WizardImport.cpp : implementation file
//

#include "stdafx.h"
#include "calendar.h"
#include "WizardImport.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CWizardImport property page

IMPLEMENT_DYNCREATE(CWizardImport, CPropertyPage)

CWizardImport::CWizardImport() : CPropertyPage(CWizardImport::IDD),
	m_btnBrowse(IDB_BROWSE, IDB_BROWSE, CSize(21,21))
{
	//{{AFX_DATA_INIT(CWizardImport)
	m_bCb = -1;
	//}}AFX_DATA_INIT
}

CWizardImport::~CWizardImport()
{
}

void CWizardImport::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CWizardImport)
	DDX_Control(pDX, IDC_EDIT1, m_ePath);
	DDX_Control(pDX, IDC_BROWSE, m_btnBrowse);
	DDX_Radio(pDX, IDC_RADIO1, m_bCb);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CWizardImport, CPropertyPage)
	//{{AFX_MSG_MAP(CWizardImport)
	ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
	ON_BN_CLICKED(IDC_RADIO1, OnRadio2)
	ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWizardImport message handlers

void CWizardImport::OnRadio2() 
{
	UpdateData(true);

	if(m_bCb == 1) {
		m_ePath.EnableWindow(true);
		m_btnBrowse.EnableWindow(true);
	} else {
		m_ePath.EnableWindow(false);
		m_btnBrowse.EnableWindow(false);
	}
}

BOOL CWizardImport::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
	
	m_bCb = 0;
	UpdateData(false);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

LRESULT CWizardImport::OnWizardNext() 
{
	UpdateData(true);
	BOOL bResult;

	if(m_bCb == 0) {
		bResult = calendar.Import(Calendar::EXPORT_CLIPBOARD, *pDay);
	}
	else {
		CString path; m_ePath.GetWindowText(path);
		bResult = calendar.Import(Calendar::EXPORT_FILE, *pDay, path);
	}

	if(!bResult) {
		return 1;
	}

	return CPropertyPage::OnWizardNext();
}

BOOL CWizardImport::OnSetActive() 
{
	CPropertySheet *pSheet = (CPropertySheet *) GetParent();
	pSheet->SetWizardButtons(PSWIZB_NEXT);
	
	return CPropertyPage::OnSetActive();
}

void CWizardImport::OnBrowse() 
{
	CFileDialog fileDlg(TRUE, ".xml", "calendar.xml", 
		OFN_HIDEREADONLY, "XML file (*.xml) | *.xml||");

	if( fileDlg.DoModal() == IDOK )	{
		m_ePath.SetWindowText(fileDlg.GetPathName());

		UpdateData(false);
	}	
}
